package com.tjbank.cssys.web.controller;


import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.tjbank.cssys.web.config.threadPoolExample.TaskOrder;
import com.tjbank.cssys.web.service.CkCreditCivilCirminalCasesService;
import com.tjbank.cssys.web.service.CkCreditOutOneReservedDataService;
import com.tjbank.cssys.web.service.CkCreditOutWuReservedDataService;
import com.tjbank.cssys.web.util.CommonResult;
import com.tjbank.cssys.web.util.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;


/**
 * 上传预留案件
 */
@RestController
@RequestMapping("/reserver")
public class CkCreditReservedController {
    @Autowired
    private CkCreditOutOneReservedDataService ckCreditOutOneReservedDataService;
    @Autowired
    private CkCreditOutWuReservedDataService ckCreditOutWuReservedDataService;
    @Autowired
    private CkCreditCivilCirminalCasesService ckCreditCivilCirminalCasesService;
    private static Logger logger = LoggerFactory.getLogger(CkCreditReservedController.class);
    /**
     * 上传预留案件
     *
     * @param jsonArray
     * @param filePath
     * @return
     */
    @PostMapping("/uploadFileRece")
    public CommonResult uploadReservidFile(@RequestBody JSONObject jsonObject, String fileName) {

        return ckCreditOutOneReservedDataService.uploadSaveOutOneReservedData(jsonObject, fileName);

    }

    /**
     * 上传司法预留案件
     *
     * @param jsonArray
     * @param bussType
     * @param filePath
     * @return
     */
    @PostMapping("/uploadFileCivil")
    public CommonResult uploadCivilFile(@RequestBody JSONObject jsonArray, String bussType, String filePath) {
        return ckCreditCivilCirminalCasesService.uploadCivilCirminal(jsonArray, bussType, filePath);
    }

    /**
     * 诉讼案件数据列表查询
     *
     * @param params
     * @return
     */
    @PostMapping("/list/data")
    public CommonResult listData(@RequestBody Map<String, String> params) {
        CommonResult result = null;
        try {
            PageInfo pageInfo = ckCreditCivilCirminalCasesService.listData(params);
            result = CommonResult.success(pageInfo, "查询成功！");
        } catch (Exception e) {
            result = CommonResult.failed(null, "");
        }

        return result;
    }

    /**
     * 司法诉讼案件上传
     *
     * @param params
     * @return
     */
    @PostMapping("/import/data")
    public CommonResult importData(@RequestBody Map<String, Object> params) {
        CommonResult result = null;
        try {

            String datas = params.get("datas").toString();
            //JSONObject dataArr = JSONObject.parseObject(datas);
            JSONArray dataArr = JSONObject.parseArray(datas);
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("jsonArray", dataArr);
            String type = params.get("type").toString();
            String fileName = params.get("fileName").toString();
            result = ckCreditCivilCirminalCasesService.uploadCivilCirminal(jsonObject, type, fileName);
        } catch (Exception e) {
            logger.error("司法诉讼异常",e.getMessage());
            result = CommonResult.failed(null, "");
        }
        return result;
    }


    @PostMapping("/selectReservedData")
    public CommonResult getReservedData(@RequestBody Map<String, String> map) {
        PageInfo pageInfo = ckCreditOutWuReservedDataService.getReservedData(map);
        return CommonResult.success(pageInfo);
    }

    @RequestMapping("/updataConfirm")
    public CommonResult updateAllotConfirm(@RequestBody Map<String,String>map){
        ckCreditOutWuReservedDataService.updateAllotConfirm(map);
        return CommonResult.success("确认成功");
    }
}
